﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using AjaxControlToolkit;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Web_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnOK.Attributes.Add("onclick", "javascript:if(confirm('" + "确认无误，并提交么？" + "')== false) return false;");
        if (!IsPostBack)
        {
            
            if (Session["用户信息.部门"].ToString() != "嘉东库")
            {
                this.Label3.Visible = false;
                this.ddlPZ.Visible = false;
            }
        }
        
    }
    public void ddlNR_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlNR.SelectedValue.ToString() == "零提")
        {
            Label9.Text = "入库车数";
            txtBad.Text = "0";
            txtBad.Attributes["contentEditable"] = "false";
            txtPB.Text = "0";
            txtPB.Attributes["contentEditable"] = "false";
            txtCC.Text = "0";
            txtCC.Attributes["contentEditable"] = "false";
            txtQH.Text = "0";
            txtQH.Attributes["contentEditable"] = "false";
            txtKX.Text = "0";
            txtKX.Attributes["contentEditable"] = "false";
            
        }
        else
        {
            decimal kxtime = BLLFactory.CreateWorkBLL().kxtj(Session["用户信息.部门"].ToString(), DateTime.Now.ToString());
            if (kxtime != 0)
            {

                txtKX.Text = kxtime.ToString("f2");
                txtKX.Attributes["contentEditable"] = "false";
            }
            else
                txtKX.Text = "";
            
            if (Session["用户信息.部门"].ToString() != "一高线")
            {
                txtQH.Text = "0";
                txtQH.Attributes["contentEditable"] = "false";
            }
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        int checkValue = 0;
        WorkInfo work = new WorkInfo();
        work.Wday = DateTime.Now.ToString();
        string nowtime = DateTime.Now.ToShortTimeString().ToString();
        string time1 = "08:00:00";
        string time2 = "20:00:00";
        string time3 = "16:00:00";
        string time4 = "23:59:59";
        DateTime dt1 = Convert.ToDateTime(nowtime);
        DateTime dt2 = Convert.ToDateTime(time1);
        DateTime dt3 = Convert.ToDateTime(time2);
        DateTime dt4 = Convert.ToDateTime(time3);
        DateTime dt5 = Convert.ToDateTime(time4);
        if (Session["用户信息.部门"].ToString() == "大棒线")
        {
            if (DateTime.Compare(dt1, dt2) <= 0)
                work.Banbie = "夜";
            else if (DateTime.Compare(dt1, dt4) <= 0)
                work.Banbie = "白";
            else
                work.Banbie = "中";
        }
        else
        {
            if (DateTime.Compare(dt1, dt2) < 0 || DateTime.Compare(dt1, dt3) > 0)
            {
                work.Banbie = "夜";
            }
            else
                work.Banbie = "白";
        }


        work.Banzu = Session["用户信息.班组"].ToString();
        work.Tianbao = Session["用户信息.姓名"].ToString();
        if (Session["用户信息.部门"].ToString() == "嘉东库")
        {
            if (ddlPZ.SelectedIndex != 0)
            {
                switch (ddlPZ.SelectedValue.ToString())
                {
                    case "线材":
                        work.Ku = "嘉东线材"; break;
                    case "螺纹":
                        work.Ku = "嘉东螺纹"; break;
                    case "卷板":
                        work.Ku = "嘉东卷板"; break;
                    case "板材":
                        work.Ku = "嘉东板材"; break;
                    default:
                        break;
                }
            }
            else
                Response.Write(" <script   language=javascript> window.alert( ' 请选择品种！ ');</script> ");
        }
        else
            work.Ku = Session["用户信息.部门"].ToString();
        
        work.Dun = Convert.ToDecimal(txtWeight.Text.ToString());
        work.Neirong = ddlNR.SelectedValue.ToString();
        work.Pos = txtPOS.Text.ToString();
        work.Pdtime = work.Wday;
        work.Num = BLLFactory.CreateWorkBLL().AUTOID(Session["用户信息.部门"].ToString());
        
        int good = 0;
        if(txtGood.Text.ToString() != "")
            good = Convert.ToInt32(txtGood.Text.ToString());
        int pb = 0;
        if(txtPB.Text.ToString() != "")
            pb = Convert.ToInt32(txtPB.Text.ToString());
        int cc = 0;
        if(txtCC.Text.ToString() != "")
            cc = Convert.ToInt32(txtCC.Text.ToString());
        int qh = 0;
        if(txtQH.Text.ToString() != "")
            qh = Convert.ToInt32(txtQH.Text.ToString());
        int h = good;
        int f = pb + cc + qh;
        if (h != f)
            Response.Write(" <script   language=javascript> window.alert( ' 平板、敞车、期货车数填写有误！ ');</script> ");
        else
        {
            checkValue = BLLFactory.CreateWorkBLL().AddWork(work);
            if (checkValue >= 1)
            {
                Response.Write(" <script   language=javascript> window.alert( ' 提交成功！ ');</script> ");
            }
        }
        
        if (txtKX.Text.ToString() != "")
        {
            BLLFactory.CreateWorkBLL().UpdateKX(work.Num, Convert.ToDecimal(txtKX.Text.ToString()));
        }
        
        if (txtGood.Text.ToString() != "0")
        {
            BLLFactory.CreateWorkBLL().UpdateGood(work.Num, Convert.ToInt32(txtGood.Text.ToString()));
        }
        if (txtBad.Text.ToString() != "")
        {
            BLLFactory.CreateWorkBLL().UpdateBad(work.Num, Convert.ToInt32(txtBad.Text.ToString()));
        }
        if (txtPB.Text.ToString() != "0")
        {
            BLLFactory.CreateWorkBLL().UpdatePb(work.Num, Convert.ToInt32(txtPB.Text.ToString()));
        }
        if (txtCC.Text.ToString() != "0")
        {
            BLLFactory.CreateWorkBLL().UpdateCc(work.Num, Convert.ToInt32(txtCC.Text.ToString()));
        }
        if (txtQH.Text.ToString() != "0")
        {
            BLLFactory.CreateWorkBLL().UpdateQh(work.Num, Convert.ToInt32(txtQH.Text.ToString()));
        }
        string sta = "配到";

        Response.Redirect(string.Format("WORK.aspx?Sta={0}", sta));

    }
    protected void btnRepeat_Click(object sender, EventArgs e)
    {
        txtWeight.Text = "";
        ddlNR.SelectedIndex = 0;
        txtPOS.Text = "";
        txtGood.Text = "";
        txtBad.Text = "";
        txtPB.Text = "";
        txtCC.Text = "";
        txtKX.Text = "";

    }
}
